//
//  EFReturnBtnCell.m
//  EnjogFood
//
//  Created by 王芳 on 17/6/11.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFReturnBtnCell.h"
#import "EFBtnTitleItem.h"

@interface EFReturnBtnCell ()
@property (strong, nonatomic) UIButton *btn;
@end

@implementation EFReturnBtnCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self initUI];
    }
    return self;
}

- (void)initUI{
    [self.contentView addSubview:self.btn];
}

- (void)setBtnTitle:(EFBtnTitleItem * )titleItem{
    if ([titleItem.title isEqualToString:@"取消"]) {
        [self.btn addTarget:self action:@selector(cancelClick) forControlEvents:UIControlEventTouchUpInside];
    }else{
        [self.btn addTarget:self action:@selector(confirmClick) forControlEvents:UIControlEventTouchUpInside];
    }
     [self.btn setTitle:titleItem.title forState:UIControlStateNormal];
}

- (void)cancelClick{
    if (self.cancelBtnClick) {
        self.cancelBtnClick();
    }
}

- (void)confirmClick{
    //保存按钮
    if (self.saveClick) {
        self.saveClick();
    }
}

- (UIButton *)btn{
    if (!_btn) {
        _btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 15, kScreenWidth - 2*20, 35)];
        _btn.backgroundColor = RGBCOLOR(0x69ba45);
        [_btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn.titleLabel.font = [UIFont systemFontOfSize:15];
        _btn.layer.cornerRadius = 5;
        _btn.layer.masksToBounds = YES;
    }
    return _btn;
}


@end
